﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Net.NetworkInformation;

namespace MiruPublic
{
    public partial class LoadingUI : UserControl
    {
        public string Title
        {
            get { return lbTitle.Text; }
            set { 
                    lbTitle.Text = value;
                    TitleChangedEventArgs args = new TitleChangedEventArgs();
                    args.Title = lbTitle;
                    OnTextChanged(args);
                }
        }

        public bool isIndeterminate
        {
            set { progressBar1.IsIndeterminate = value; }
            get { return progressBar1.IsIndeterminate; }
        }
        public double Value
        {
            get { return progressBar1.Value; }
            set { progressBar1.Value = value; }
        }
        private string _NetWorkErrorMessage = "Hiện không có kết nối mạng (wifi/cellular..)\nVui lòng kiểm tra và thử lại!";

        public string NetWorkErrorMessage
        {
            set { _NetWorkErrorMessage = value; }
            get { return _NetWorkErrorMessage; }
        }
        public LoadingUI()
        {
            InitializeComponent();

            //if (NetworkInterface.GetIsNetworkAvailable() != true)
            //{
            //    MessageBox.Show(NetWorkErrorMessage);

            //    return;
            //}
        }
        
        public event EventHandler<TitleChangedEventArgs> TitleChanged;

        public virtual void OnTextChanged(TitleChangedEventArgs e)
        {
            EventHandler<TitleChangedEventArgs> handler = TitleChanged;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }
    public class TitleChangedEventArgs : EventArgs
    {
        public TextBlock Title { get; set; }
    }
}
